<?php

namespace App\Model;


use Illuminate\Support\Facades\DB;

class Anonym extends BaseModel
{
    protected $connection = 'api';
    protected $table_scene = 'anonmy_scene';
    protected $table_role = 'anonmy_role';
    protected $table_interact = 'anonmy_interact';


    public function getSceneList($input = [])
    {
        $limit = $input['limit'] ?? 10;
        $res = DB::connection($this->connection)->table($this->table_scene)
            ->paginate($limit);
        return $this->objToArray($res);
    }

    public function getRoleList($scene_id){
        $res = DB::connection($this->connection)->table($this->table_role)
            ->where('scene_id' ,$scene_id)
            ->get();
        return $this->objToArray($res);
    }

    public function getInteractList($scene_id){
        $res = DB::connection($this->connection)->table($this->table_interact)
            ->where('scene_id' ,$scene_id)
            ->get();
        return $this->objToArray($res);
    }

    public function createOrUpdateScene($data){
        return curl_request(getKkaudioApiUrl() . '/inner/anonym_chat/scene_upsert', $data, 'json', 'POST');
    }
    public function createOrUpdateRole($data){
        return curl_request(getKkaudioApiUrl() . '/inner/anonym_chat/role_upsert', $data, 'json', 'POST');
    }
    public function createOrUpdateInteract($data){
        return curl_request(getKkaudioApiUrl() . '/inner/anonym_chat/interact_upsert', $data, 'json', 'POST');
    }
    public function delInteract($id){
        return curl_request(getKkaudioApiUrl() . '/inner/anonym_chat/interact_del', ['id' => $id], 'urlencoded', 'GET');
    }
}
